"""
演示Python pymysql库的基础操作
"""

from pymysql import Connection
connection = Connection(
    host="localhost", # 主机名
    port=3306, # 端口
    user="root", # 账户
    password="root" # 密码
)
# print(connection.get_server_info())
# 执行非查询性质SQL
cursor = connection.cursor() # 获取到游标对象
# cursor.execute("create database test")
# 选择数据库
connection.select_db("test")
# 执行sql
# cursor.execute("create table pymysql_test(id int, name varchar(30))")

# 执行查询性质SQL
cursor.execute("select * from student")
result: tuple = cursor.fetchall()
for r in result:
    print(r)

# 关闭连接
cursor.close()